<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib uri="/mytag" prefix="yjd"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>医美分期-JOB监控</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<link href="${requestScope.FPWEB.staticRootPath }/Css/Admin/Admin.css" rel="stylesheet" />
<script src="${requestScope.FPWEB.staticRootPath }/Js/Plugins/Jquery/1.8.0/Jquery.js"></script>
<style type="text/css">
.level {
	padding: 5px;
	background: #fff;
	border-radius: 5px;
	display: block;
	width: 60px;
	text-align: center;
}

.level-1 {
	background: #FFF;
}

.level-2 {
	background: #fee0a7;
}

.level-3 {
	background: #fdc2c8;
}

.level-4 {
	background: #a7feb2;
}
</style>
</head>
<body>
	<div class="wrap">
		<form action="<yjd:url url="/job/add"/>" method="get" autocomplete="off">
			<div class="search_type cc">
				<button type="submit" class="btn btn_submit length_1">添加任务</button>
			</div>
		</form>
		<div class="table_list">
			<table width="100%">
				<thead>
					<tr>
						<td width="50">ID</td>
						<td width="150">功能描述</td>
						<td width="100">是否执行</td>
						<td width="100">表达式</td>
						<td width="100">上次执行时间</td>
						<td width="100">下次执行时间</td>
						<td width="150">Options</td>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${definedJobs }" var="job">
					<tr>
						<td>${job.id_job }</td>
						<td>${job.description }</td>
						<td>
						<c:if test="${job.enable == 0}"><span style="color: red;">不执行</span></c:if>
						<c:if test="${job.enable == 1}"><span style="color: green;">执行</span></c:if>
						</td>
						<td>${job.cron }</td>
						<td>
						<c:if test="${job.last_exectime == 0}">未知</c:if>
						<c:if test="${job.last_exectime != 0}"><yjd:jstl_date value="${job.last_exectime }" parttern="yyyy-MM-dd HH:mm:ss"/></c:if>
						</td>
						<td>
						<c:if test="${job.next_exectime == 0}">未知</c:if>
						<c:if test="${job.next_exectime != 0}"><yjd:jstl_date value="${job.next_exectime }" parttern="yyyy-MM-dd HH:mm:ss"/></c:if>
						</td>
						<td>
						    <label><a class="btn" href="<yjd:url url="/job/update/${job.id_job }"/>">更新</a></label>
							<label><a class="btn" href="javascript:handler_job('<yjd:url url='/job/call/${job.id_job }'/>');">手动调用</a></label>
						</td>
					</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
function handler_job(call_url){
	if(confirm("确定要执行该JOB吗？")){
		$.ajax({
			type:"get",
			url:call_url,
			timeout:3000,
			cache:false,
			async:true,
			beforeSend:function(){
				
			},
			success:function(data){
				console.log(data);
				if(data.state==1){
					alert('执行成功！');
					 location.reload();
				}else if(data.state==0){
					alert('执行失败,原因:'+data.message);
				}
			},
			error:function(msg){
			}
		});
	}
}
</script>